package com.demo.androidtest;

import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.demo.MainActivity;
import com.demo.androidTest.Calc;
import com.demo.gson.GsonTest;
import com.yihujiu.demo.R;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

/**
 * Created by yi.zhe on 2018/3/5.
 */

@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityInstrumentationTest {
    private static final String STRING_TO_BE_TYPED = "androidTest";

    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
            MainActivity.class);

    @Test
    public void sayHello() {
        //Gson
        GsonTest gt = new GsonTest();
        gt.fromJson();

        //逻辑测试DEMO
        Calc c = new Calc();
        //assertEquals(2, c.init2());

        //获取editText并输入字符串
        //onView(withId(R.id.et)).perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard()); //line 1

        //比较应用中textView与期望字符自否匹配
        String expectedText = "安卓DEMO";
        onView(withId(R.id.tv)).check(matches(withText(expectedText))); //line 3

        //获取button并模拟点击
        //onView(withText("Say hello!")).perform(click()); //line 2
        onView(withId(R.id.btnAnnotation)).perform(click());
    }
}
